﻿using IM.Easy.Core.Attributes;
using IM.Easy.Entity.Log;
using IM.Easy.Infrastructure.Query;
using IM.Easy.LogServices.Dtos;
using IM.Easy.LogServices.IServices;
using Microsoft.AspNetCore.Mvc;

namespace IM.Easy.Api.Controllers.Log
{
    [Route("log/exception")]
    public class ExceptionLogController : ControllerBase
    {
        private readonly IExceptionLogService _exceptionLogService;
        public ExceptionLogController(IExceptionLogService exceptionLogService)
        {
            _exceptionLogService = exceptionLogService;
        }

        /// <summary>
        /// 获取异常日志列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        [Api(Name = "异常日志列表", Perm = "exception:log:list")]
        public PageResponse<ExceptionLogDto> GetList([FromQuery] ExceptionLogQueryDto query)
        {
            return _exceptionLogService.GetList(query);
        }

        /// <summary>
        /// 根据ID获取SysExceptionLog对象
        /// </summary>
        /// <param name="id">对象的ID</param>
        /// <returns>返回指定的SysExceptionLog对象</returns>
        [HttpGet("{id}")]
        [Api(Name = "异常日志详情", Perm = "exception:log:info")]
        public SysExceptionLog GetById(Guid id)
        {
            var result = _exceptionLogService.GetById(id);
            return result ?? throw new KeyNotFoundException($"未找到ID为 {id} 的SysExceptionLog对象。");
        }

        /// <summary>
        /// 删除SysExceptionLog对象
        /// </summary>
        /// <param name="ids">对象的IDS</param>
        [HttpDelete]
        [Api(Name = "删除异常日志", Perm = "exception:log:delete")]
        public void Delete([FromBody] Guid[] ids)
        {
            _exceptionLogService.Delete(ids);
        }
    }
}
